<!--点击复制-->
<script setup>
import {ElementUtils} from "@/assets/js/ElementUtils";
import {toRefs} from "vue";
import useClipboard from 'vue-clipboard3'

const props = defineProps({
    text: {required: true},
});

const {text} = toRefs(props)

const {toClipboard} = useClipboard()

const emit = defineEmits(['success'])

const onClick = async () => {
    try {
        await toClipboard(text.value + '')
        ElementUtils.notice({
            message: "复制成功",
        })
        emit("success")
    } catch (e) {
        ElementUtils.notice({
            message: "复制失败",
            type: "warning",
        })
        console.warn(e)
    }
}
</script>

<template>
    <span class="clickable" @click="onClick">
      <slot/>
    </span>
</template>

<style scoped>

</style>